/**
 * 两个有序序列A和B，合并成C
 * 问C中是否存在两个连续的元素均来自于A
 * 首先合并出C，然后枚举C的每一对位置即可
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vll = vector<llt>;

template<typename T>
void input(vector<T> & a, int n){
    a.assign(n + 1, {});
    for(int i=1;i<=n;++i) cin >> a[i];
    return;
}

template<typename T>
istream & operator >> (istream & is, vector<T> & v){
    for(auto & i : v) is >> i;
    return is;
}

int N, M;
vi A, B, C;

bool proc(){
    int ia = 0, ic = 0;
    while(1){
        if(A[ia] > C[ic]){
            ic += 1;
            if(ic == N + M) break;   
        }else if(A[ia] < C[ic]){
            ia += 1;
            if(ia == N) break;
        }else{
            if(ia + 1 < N and ic + 1 < N + M){
                if(A[ia + 1] == C[ic + 1]){
                    return true;
                }
            }

            ia += 1, ic += 1;
            if(ia >= N or ic >= N + M) break;
        }
    }
    return false;
}

void work(){
    cin >> N >> M;
    A.assign(N, {});
    B.assign(M, {});
    cin >> A >> B;
    sort(A.begin(), A.end());
    C.assign(N + M, {});
    copy(A.begin(), A.end(), C.begin());
    copy(B.begin(), B.end(), C.begin() + N);
    sort(C.begin(), C.end());
    cout << (proc() ? "Yes\n" : "No\n");
    return; 
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;

    while(nofkase--) work();
    return 0;
}